package com.endi.sap.dingding;

import com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDHeaders;
import com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDRequest;
import com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDResponse;
import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teautil.models.RuntimeOptions;
import com.endi.sap.entity.BaseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 根据实例ID获取表单数据
 */
@Component
public class QueryDataByInstId {

    @Autowired
    private CreateDingClient createDingClient;

    public GetFormDataByIDResponse query(BaseInfo baseInfo,String formInstId){

        try {
            com.aliyun.dingtalkyida_1_0.Client client = createDingClient.createClient();
            GetFormDataByIDHeaders getFormDataByIDHeaders = new GetFormDataByIDHeaders();
            getFormDataByIDHeaders.xAcsDingtalkAccessToken = baseInfo.getAccessToken();
            GetFormDataByIDRequest getFormDataByIDRequest = new GetFormDataByIDRequest();
            getFormDataByIDRequest.setSystemToken(baseInfo.getAppToken());
            getFormDataByIDRequest.setUserId(baseInfo.getUserId());
            getFormDataByIDRequest.setAppType(baseInfo.getAppkey());
            try {
                GetFormDataByIDResponse response = client.getFormDataByIDWithOptions(formInstId, getFormDataByIDRequest, getFormDataByIDHeaders, new RuntimeOptions());
                return response;
            } catch (TeaException err) {
                if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                    // err 中含有 code 和 message 属性，可帮助开发定位问题
                }

            } catch (Exception _err) {
                TeaException err = new TeaException(_err.getMessage(), _err);
                if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                    // err 中含有 code 和 message 属性，可帮助开发定位问题
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
